<template>
  <van-nav-bar
    left-arrow
    fixed
    placeholder
    :title="title"
    :right-text="rightText"
    @click-right="emit('click')"
    @click-left="clickLeft"
  />
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()
interface Props {
  title?: string
  rightText?: string
  onBack?: () => void
}
const prop = defineProps<Props>()

interface Emits {
  (name: 'click'): void
}
const emit = defineEmits<Emits>()

const clickLeft = () => {
  if (prop.onBack) {
    prop.onBack()
    return
  }
  router.back()
}
</script>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
